package com.beiding.jsonanalyzer.analyze.query;

import com.beiding.jsonanalyzer.analyze.func.FuncBase;
import com.beiding.jsonanalyzer.analyze.func.FuncFactory;
import com.beiding.jsonanalyzer.analyze.func.openfunc.FuncUtils;

/**
 * 值比较器
 * 可指定key和比较方式
 */
public class ValueConditionFactory implements FuncFactory<FuncBase<ComparatorResult>> {

    private FuncFactory field;

    private Comparator comparator;

    private FuncFactory value;

    public ValueConditionFactory(Object field,Object value, Comparator comparator) {
        this.field = FuncUtils.ensureFuncFactory(field);
        this.comparator = comparator;
        this.value = FuncUtils.ensureFuncFactory(value);
    }


    @Override
    public SimpleCondition createInstance() {
        return new ValueCondition(field.createInstance(), value.createInstance(), comparator);
    }
}
